import { acrossModel } from '@/types/model'
import { AbstractDraw } from './AbstractDraw'

export class DrawAcross extends AbstractDraw {
  constructor(ctx: CanvasRenderingContext2D, startY: number, private lst_across: acrossModel[]) {
    super(ctx, startY)
  }

  /**
   * 绘制控制点
   * @param ctx 画笔
   * @param lst_across 控制点集合
   */
  public draw(): void {
    for (const across of this.lst_across) {
      this.drawAcrossXY(across)
      this.drawAcrossText(across)
    }
  }

  private drawAcrossXY = (across: acrossModel) => {
    const [x, y] = JSON.parse(across.xy!)
    super.drawCircle(super.scaleXY(x, y), 2, 'red')
    super.drawCircle(super.scaleXY(x, y), 6, 'green')
  }

  private drawAcrossText = (across: acrossModel) => {
    const [x, y] = JSON.parse(across.xy!)
    super.drawText(across.acrossName, super.scaleXY(x + 10, y + 5), 'black', 'left', 'bottom')
    super.drawText(across.acrossY.toString() + 'm', super.scaleXY(x + 10, y - 10), '#8CABD9', 'left', 'bottom')
  }
}
